package main

import (
	"fmt"
	"path/filepath"
	"strings"
)

func main() {
	p := filepath.Join("/", "tmp", "file.txt")
	fmt.Println(p)

	fmt.Println(filepath.Join("dir1//", "filename"))

	fmt.Println(filepath.Join("dir1/../dir2", "filename"))

	fmt.Println(filepath.Join("dir1/../dir2", "../dir3"))
	p1 := filepath.Join(p, "dir3/")
	fmt.Println(p1)

	fmt.Println("Dir(p): ", filepath.Dir(p1))
	fmt.Println("Base(p)", filepath.Base(p1))

	fmt.Println(filepath.IsAbs("dir/file"))
	fmt.Println(filepath.IsAbs("/dir/file"))

	ext := filepath.Ext(p)
	fmt.Println("extension: ", ext)

	fmt.Println(strings.TrimSuffix(p, ext))

	rel, err := filepath.Rel("a/b", "a/b/t/file")
	if err != nil {
		panic(err)
	}
	fmt.Println(rel)

	rel, err = filepath.Rel("a/b", "a/c/t/file")
	if err != nil {
		panic(err)
	}
	fmt.Println(rel)
}
